package com.carworld.controller;

import java.text.DecimalFormat;
import java.util.Date;

import com.carworld.config.BaseController;
import com.carworld.model.ShopOrder;
import com.carworld.model.SysUser;
import com.carworld.model.UserAdvice;
import com.carworld.utils.DateUtils;
import com.jfinal.kit.StrKit;
import com.jfinal.weixin.sdk.api.ApiResult;
import com.jfinal.weixin.sdk.api.TemplateData;
import com.jfinal.weixin.sdk.api.TemplateMsgApi;

public class TestController extends BaseController {
	public static Integer order_paid_status = 1;
	public void test()  {
		// 获取分红股东openId 
//		String orderId= getPara("orderId");
//		ShopOrder order = ShopOrder.dao.findOrderInfo(orderId);
//		
//		System.out.println(order.getShopOrderStatus() == order_paid_status);
//		System.out.println(order_paid_status.equals(order.getShopOrderStatus()));
//		String shareholderIdOpenId = SysUser.dao.findByIdInCache("8ded7a533c5f45f3ac5dfa2e241b5671").getUserOpenid();
//		Boolean isdividend = false;
//		String dividendSumOfShareholder = null; // 调取查询分红的API
//		String URL = "http://47.92.137.225/carWorld/doOrderCount?id=" + orderId;
//		String dividendContent = null;
//		try {
//			dividendContent = HttpUtil.getContentFromUrl(URL);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		if (dividendContent != null) {
//			JSONObject json = JSONObject.parseObject(dividendContent);
//			System.out.println("json:" + json.toString());
//			dividendSumOfShareholder = String.valueOf(json.getJSONObject("body").get("dividendGDTotal"));
//			if (dividendSumOfShareholder != null) {
//				isdividend = true;
//			} else {
//				System.out.println("暂时没有分红");
//			}
//			System.out.println("dividend:" + dividendSumOfShareholder);
//		}
//		System.out.println("isdividend--》" + isdividend);
		

		 // 通知股东分红收入
			ApiResult apiResult = TemplateMsgApi.send(TemplateData.New().setTouser("ovswp0lhfdPHEo4FaY2CSwjRNLbo")
					.setTemplate_id("kDim1M1Hw-uNUWP9LVvRwLz-aEnDKNybd7t5AJZ8kG0") //收益到账通知模板id
					.setUrl("http://b.food.3kkk.xyz/carworld_weixin/pages/page_dividendList.html")
					.add("first", "新的分红收益消息提示：\n").add("keyword1", "3.72元", "#173177")
					.add("keyword2", "来自【张怡】的消费", "#173177")
					.add("keyword3", "2019-10-09 16:18:44" + "\n", "#173177")
					.add("remark", "来自【茉德精品火锅】的温馨提示", "#173177").build());
			System.out.println("通知股东模板消息结果：" + apiResult.getJson());
		
	}

	public void bind() {
		
		ApiResult apiResult = TemplateMsgApi.send(TemplateData.New().setTouser("ocgWcwsiSnCurAAjtyk58vEVuI6s")// 消息接收者
				.setTemplate_id("4EfN-C8J0DbTe9sxqvlRX266mF1fQ1MgarJ-wD-MWV4") // 新会员加入的模板id
				.setUrl("http://food.3kkk.xyz/carworld_weixin/pages/page_userCenter/myMembers.html")
				// 模板参数
				.add("first", "您有新的人脉会员加入\n")
				.add("keyword1", DateUtils.getCurrentTime(new Date()) + "\n", "#173177")
				.add("keyword2", "安子烨", "#173177")
				.add("keyword3", "茉德精品火锅普通会员", "#173177")
				.add("keyword4", DateUtils.getCurrentTime(new Date()) + "\n", "#173177")
				.add("remark", "该会员通过您的推广码加入，推广效果显著，继续加油哦~", "#173177").build());
		System.out.println("通推广者模板消息结果：" + apiResult.getJson());
	
	}
	// 预约成功后通知店长
		public void tttt(){
		ApiResult apiResultOfOfficer = TemplateMsgApi.send(TemplateData.New()
				.setTouser("ocgWcwiaISXLqsy1E5a-NulA2RHM")// 消息接收者
				.setTemplate_id("M5IB6rb8fbBPLRtMbn_tDGim9JjHJ7YYq8xERjX_EJE") // 客户预约通知的模板id
				// 模板参数
				.add("first", "有新的客户预约，请及时确认\n")
				.add("keyword1","茉德火锅店" , "#173177")//userReserve.getUserName()
				.add("keyword2", "2人", "#173177")
				.add("keyword3", "2012-21", "#173177")
				.add("keyword4", "110" + "\n", "#173177")
				.add("keyword5", "gsaf" + "\n", "#173177")
				.add("remark", "请在pc端处理该预约", "#173177").build());
		System.out.println("通知店长模板消息结果：" + apiResultOfOfficer.getJson());
	}
	
	
	public void order()  {
		 ShopOrder.dao.paid("1572268984054",2028,"61e2dba35cf14180a7097e56c33fc244",2);
	}

	public void notifydividend()  {
		 ShopOrder.dao.paid("1572268984054",2028,"61e2dba35cf14180a7097e56c33fc244",2);
	}


	public void sendAdvice(){
		// 获取分红股东openId
		String shareholderIdOpenId ="ocgWcwiaISXLqsy1E5a-NulA2RHM";
		String notificatedShareholderUrl = "http://food.3kkk.xyz/carworld_weixin/dividend/getIncomeTodyCount?shareholderId=cb6ae32529be446a837b825ba766c2ed";
		// 通知股东分红收入

		ApiResult apiResult = TemplateMsgApi.send(TemplateData.New().setTouser("ocgWcwsiSnCurAAjtyk58vEVuI6s")
					.setTemplate_id("8rEWeq2m5sFkS877q3N2p_5x-eCWzWszI3e_-TMwtlI") // 收益到账通知模板id  8rEWeq2m5sFkS877q3N2p_5x-eCWzWszI3e_-TMwtlI
					.setUrl("http://food.3kkk.xyz/carworld_weixin/dividend/getIncomeTodyCount?shareholderId=cb6ae32529be446a837b825ba766c2ed")
					.add("first", "新的分红收益消息提示：\n")
					.add("keyword1", "3" + "元", "#173177")
					.add("keyword2", "来自【小娃测试】的消费", "#173177")
					.add("keyword3", DateUtils.getCurrentTime(new Date()) + "\n", "#173177")
					.add("remark", "点击查看分红详情", "#173177").build());
	}
	
	
	public static void main(String[] args) {

		UserAdvice advice=new UserAdvice();
	    TestController tttt=new TestController();
	    tttt.sendAdvice();
	}

	

}
